package com.heo.music.player.entity;

import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import java.util.Date;

/**
 * 通用实体
 * created on 2023-06-07 16:04
 *
 * @author 星天无极
 **/
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Data
public class BaseEntity {

    @Column(nullable = false)
    protected Boolean isDeleted;

    @Column(nullable = false, updatable = false)
    @CreatedDate
    protected Date createTime;

    @Column(nullable = false)
    @LastModifiedDate
    protected Date updateTime;

    @PrePersist
    public void setIsDeleted() {
        isDeleted = false;
    }
}
